import { createStore } from "vuex";
import Cookies from 'js-cookie';
export default createStore({
  state: {
	  userInfo:{},
	  on_line:false,
	  orders:[],//待确认订单
  },
  mutations: {
	  //用户已登录
	  onlogin(state){
	  		state.on_line = true;
	  },
	  //退出登录
	  outlogin(state){
			state.on_line = false;
			localStorage.removeItem('account');
			localStorage.removeItem('token');
			localStorage.removeItem('token_type');
			localStorage.removeItem('refresh_token');
			localStorage.Online = false;
	  },
	  setUserInfo(state,data){
			state.userInfo=data;
	  },
	  setUserImg(state,data){
			state.userInfo.img=data;
	  },
	  setOrders(state,data){
			state.orders = data;
			//console.log("收到待确认订单",data);
	  }
  },
  getters:{
	  //验证在线状并将结果返回
	  hasOnline(state){
	  	state.on_line = (!localStorage.Online || localStorage.Online=='false' || localStorage.Online==undefined)?false:true;
		//console.log("在线状态",state.on_line);
		return state.on_line;
	  },
	  token(){
		  return localStorage.token_type+' '+ localStorage.token;
	  },
  },
  actions: {},
  modules: {},
});
